<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue自加练习-简易计算器</title>
    <script src="../../js/vue.js"></script>
    <!-- 编写一个加减乘除简易计算器 -->
   
    <style>
        #app{
            width: 50%;
            margin: 3rem auto;
            display: flex;
            justify-content: space-around;
        }
        input{
            width: 2rem;
            text-align: center;
          
        }
        span{
            color: red;
          
        }
    </style>
</head>
<body>
    <div id="app">
        <h2>
            <input type="text" v-model="number_1"> 
            <button v-on:click="add">+</button>
            <button v-on:click="sub">-</button>
            <button v-on:click="cheng">*</button>
            <button v-on:click="chu">/</button>
            <input type="text" v-model="number_2">
            =
            <span>{{count}}</span>
        </h2>  
    </div>
    <script>
        var v_app = new Vue({
            el:"#app",
            data:{
                number_1:0,
                number_2:0,
                count:0
            },
            methods:{
                add:function(){
                    this.count = Number(this.number_1)+Number(this.number_2)
                },
                sub:function(){
                    this.count = Number(this.number_1)-Number(this.number_2)
                },
                cheng:function(){
                    this.count = Number(this.number_1)*Number(this.number_2)
                },
                chu:function(){
                    this.count = Number(this.number_1)/Number(this.number_2)
                }
            }
        })
    </script>
</body>
</html>